math.randomseed(os.time())
local Game = require "Game"

local Map = require "Map"
local Tile = require "Tile"

local maptiles = {}
anchorPointValues = {"N","NE","SE","S","SW","NW"};
periodOfDayValues = {"birdsong", "sunrise", "daylight", "Sunset", "Evening", "Midnight"}

rand = function (upper)
	math.random()
	math.random()
	math.random()
	math.random()
	math.random()
	math.random()
	return math.random(upper)
end

--[[
-- Careful of random number seeding here- you will need to randomly
-- seed before calling this
function randomlist(l, samp)
  local newlist
  newlist = {}
  if not samp then
    samp = 0
  else
    samp = #l - samp
  end
  while #l > samp do
    local idx
    idx = math.random(1, #l)
    newlist[#newlist + 1] = l[idx]
    table.remove(l, idx)
  end
  return newlist
end ]]

-- returns the corresponding index number from a table array
function GetIndexFromTable(t, value)
	foundIndex = nil;

	for i, v in pairs(t) do
		if v == value then
			foundIndex = i;
			break;
		end
	end

	return foundIndex;
end

-- not sure how to get this inside the game.lua module
-- my previous efforts didn't work as the entry call failed
function LoadMapTiles(t)
	tile = Tile:new(t);
	table.insert(maptiles, tile)
end

game = Game:new()
game.map = Map:new()
--game:LoadGameObjects()

entry = LoadMapTiles;
dofile("tiles.db");
game.tiles = maptiles;
game:SetupMap();

print("Tile placement order");
for i, v in ipairs(game.map.tilePlacementOrder) do print(v.name) end;


print("COORDS LIST");
for i, v in pairs(game.map.coordinates) do
	print(i,v);
	print(v.x .. "," .. v.y);
end;

print("TILE EDGE LIST");
for i, tile in pairs(game.map.tiles) do
	print("Name: " .. tile.name);
	print("Coords: ".. tile:PrintCoordinates() );
	print(tile.coordinates);
	for j, edge in pairs(tile.tileEdges) do
		print(j,edge);
		print(edge.x .. "," .. edge.y);
	end;
end;
